# -*- coding: utf-8 -*-

import pandas as pd

from pipe.readExcel import readExcelWithSheetName


def compare(df1, dt2, jizhunfield):
    # 读取两个表
    # dt1 = pd.read_excel(datapath1, sheet_name=sheetname1)
    # dt2 = pd.read_excel(datapath2, sheet_name=sheetname2)
    # 确定基准列
    dt1_name = df1[jizhunfield].values.tolist()
    dt2_name = dt2[jizhunfield].values.tolist()
    # // dt1中没有导师列，需先添加
    df1['导师'] = '';

    for i in dt1_name:
        if i in dt2_name:
            dt2_row = dt2.loc[dt2[jizhunfield] == i]
            # dt1_row = dt1.loc[dt1['学号'] == i]
            # dt1 = dt1[dt1['学号'] == i]
            # print(type(dt2_row['导师']))
            rowi = df1.index[df1[jizhunfield] == i].tolist()
        df1.loc[rowi, '导师'] = dt2_row['导师'].tolist()  # // 指定行和列进行赋值
    print(df1)
    df1.to_csv('D:/在校生(含导师).csv', header=True, index=False,
               encoding="utf_8_sig")  # // 转csv时为防止出现乱码，需要添加utf8


if __name__ == '__main__':
    datapath1 = r"E:\项目相关\13.可再生能源补贴\殷甲伟\2.可再生能源系统测试\2023.11.12报告测试情况\2023.11.12资质中心10月份数据.xlsx"
    sheetname1 = "sheet1"
    datapath2 = r"E:\项目相关\13.可再生能源补贴\殷甲伟\2.可再生能源系统测试\2023.11.12报告测试情况\2023.11.12资质中心10月份数据.xlsx"
    sheetname2 = "sheet1"
    jizhunfield="学号"
    df1=readExcelWithSheetName(datapath1,sheetname1)
    df2=readExcelWithSheetName(datapath2,sheetname2)
    compare(df1,df2,jizhunfield)
